<?php


namespace app\modules\Merchant\models;

use Illuminate\Database\Eloquent\SoftDeletes;

class bankModel extends \Illuminate\Database\Eloquent\Model
{
    protected $table = 'dianpu_bank';
    protected $primaryKey = 'id';

    protected static $ALLTYPE = [
        'bank'=>'银行卡转账',
        'wechat'=>'微信零钱',
        'alipay'=>'支付宝'
    ];
    protected function serializeDate($date)
    {
        return $date->format('Y-m-d H:i:s');
    }

    public function getTypeNameAttribute($value)
    {
        return self::$ALLTYPE[$this->attributes['type']]??'未知';
    }

    public static function getAllType()
    {
        return self::$ALLTYPE;
    }

    public static function getAllBankType()
    {
        $all_type = \configModel::query()->where('type', 29)->where('key', 'merchant_withdraw_type')->value('value');
        $data = [];
        if(!empty($all_type)){
            $all_type_arr = json_decode($all_type, true);
            foreach ($all_type_arr as $text){
                if($text === '微信零钱'){
                    array_push($data, ['type'=> 'wechat','name'=>'微信零钱']);
                }
                if($text === '手动线下打款'){
                    array_push($data, ['type'=> 'bank','name'=>'银行卡转账']);
                }
                if($text === '支付宝'){
                    array_push($data, ['type'=> 'alipay','name'=>'支付宝']);
                }
            }
        }
        return $data;
    }
}